<?php

namespace common\services\expcenter;

use common\services\BaseService;
use common\repositories\expcenter\ExpCenterRepository;

class ExpCenterService extends BaseService {

    public $_ExpCenterRepository;

    public function __construct(ExpCenterRepository $ExpCenterRepository) {
        $this->_ExpCenterRepository = $ExpCenterRepository;
    }

    /**
     * @param \common\models\expcenter\ExpCenterModel $model
     * @return mixed
     */
    public function saveExpCenter($model) {
        if (isset($model->uid) && !empty($model->uid)) {
            //修改
            $model->pwd = $model->pwd;
            $result = $this->_ExpCenterRepository->updateExpCenter($model);
        } else {
            //新增
            $model->pwd = $model->pwd;
            $model->status = ExpCenterRepository::STATUS_YES;
            $result = $this->_ExpCenterRepository->addExpCenter($model);
        }
        if($result == false) {
            $this->setAndReturn($this->_ExpCenterRepository->getErrCode(), $this->_ExpCenterRepository->getErrMsg());
        }
        return $result;
    }

    /**
     * 更新密码
     * @param int $uid
     * @param string $pwd
     */
    public function updatePwd($uid,$pwd) {
        if (!empty($uid)) {
            return $this->_ExpCenterRepository->updatePwd($uid,$pwd);
        }
    }

    /**
     * 更新状态
     * @param int $uid
     * @param int $status
     */
    public function updateStatus($uid) {
        if (!empty($uid)) {
            return $this->_ExpCenterRepository->updateStatus($uid);
        }
    }

    public function getUserList($limit) {
        return $this->_ExpCenterRepository->getExpCenterUsers($limit);
    }

    public function getUserCount() {
        return $this->_ExpCenterRepository->getExpCenterUsersCount();
    }
}